package com.xbongbong.saas.enums.business;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.ScreenTypeEnum;
import com.xbongbong.saas.enums.SetTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.base.ContractBaseEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 合同枚举
 *
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/18 19:31
 * @since v1.0
 */
@Getter
public enum ContractEnum {
    // 合同模板设置字段
    // 基本信息
    BASE_INFO(ContractBaseEnum.BASE_INFO.getAttr(), "enum.contract.attrName.base_info", "baseInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 10000, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    CONTRACT_NO(ContractBaseEnum.CONTRACT_NO.getAttr(), "enum.contract.attrName.contract_no", "contractNo", FieldTypeEnum.SERIALNO.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9990, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    NAME("text_1", "enum.contract.attrName.name", "name", FieldTypeEnum.TEXT.getType(), 4, 0, 0, ShowTypeEnum.ALL.getCode(), 9980, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    LINK_CUSTOMER(ContractBaseEnum.LINK_CUSTOMER.getAttr(), "enum.contract.attrName.link_customer", "linkCustomer", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9970, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    LINK_CONTACT(ContractBaseEnum.LINK_CONTACT.getAttr(), "enum.contract.attrName.link_contact", "linkContact", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9960, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    LINK_OPPORTUNITY("text_4", "enum.contract.attrName.link_opportunity", "linkOpportunity", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9950, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    SIGN_PERSON(ContractBaseEnum.SIGN_PERSON.getAttr(),"enum.contract.attrName.sign_person", "signPerson", FieldTypeEnum.USER.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9940, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    SIGN_TIME(ContractBaseEnum.SIGN_TIME.getAttr(), "enum.contract.attrName.sign_time", "signTime", FieldTypeEnum.DATETIME.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    DEADLINE(ContractBaseEnum.DEADLINE.getAttr(), "enum.contract.attrName.deadline", "deadLine", FieldTypeEnum.DATETIME.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    STATUS(ContractBaseEnum.STATUS.getAttr(), "enum.contract.attrName.status", "status", FieldTypeEnum.COMBO.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9910, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    OWNER_ID(ContractBaseEnum.OWNER_ID.getAttr(),"enum.contract.attrName.owner_id", "ownerId", FieldTypeEnum.OWNERID.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9900, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    MINOR_USER(ContractBaseEnum.MINOR_USER.getAttr(), "enum.contract.attrName.minor_user", "coUserId", FieldTypeEnum.COUSERID.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9890, 1, 0, ScreenTypeEnum.SCREEN_SEARCH.getType()),
    // 销售信息
    SALE_INFO(ContractBaseEnum.SALE_INFO.getAttr(), "enum.contract.attrName.sale_info", "saleInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9880, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    PRODUCT(ContractBaseEnum.PRODUCT.getAttr(), "enum.contract.attrName.product", "products", FieldTypeEnum.SELECT_PRODUCT.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9870, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    PRODUCT_TOTAL(ContractBaseEnum.PRODUCT_TOTAL.getAttr(), "enum.contract.attrName.product_total", "productTotal", FieldTypeEnum.NUM.getType(), 3, 1, 0, ShowTypeEnum.ALL.getCode(), 9860, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    OTHER_EXPENSE("num_27", "enum.contract.attrName.other_expense", "otherExpense", FieldTypeEnum.NUM.getType(), 3, 1, 0, ShowTypeEnum.ALL.getCode(), 9850, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    DISCOUNT_AMOUNT(ContractBaseEnum.DISCOUNT_AMOUNT.getAttr(),"enum.contract.attrName.discount_amount", "discountAmount", FieldTypeEnum.NUM.getType(), 3, 1, 0, ShowTypeEnum.ALL.getCode(), 9840, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    AMOUNT(ContractBaseEnum.AMOUNT.getAttr(), "enum.contract.attrName.amount", "totalMoney", FieldTypeEnum.NUM.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9830, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    CONTRACT_COST(ContractBaseEnum.CONTRACT_COST.getAttr(), "enum.contract.attrName.contract_cost", "contractCost", FieldTypeEnum.NUM.getType(),SetTypeEnum.DISABLE_OPEN.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9820, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    GROSS_PROFIT(ContractBaseEnum.GROSS_PROFIT.getAttr(), "enum.contract.attrName.gross_profit", "grossProfit", FieldTypeEnum.NUM.getType(), SetTypeEnum.DISABLE_OPEN.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9810, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    GROSS_PROFIT_RATE(ContractBaseEnum.GROSS_PROFIT_RATE.getAttr(),"enum.contract.attrName.gross_profit_rate", "grossProfitRate", FieldTypeEnum.NUM.getType(), SetTypeEnum.DISABLE_OPEN.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9800, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    CASH_PROFIT(ContractBaseEnum.CASH_PROFIT.getAttr(), "enum.contract.attrName.cash_profit", "cashProfit", FieldTypeEnum.NUM.getType(), SetTypeEnum.DISABLE_OPEN.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9790, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    CASH_PROFIT_RATE(ContractBaseEnum.CASH_PROFIT_RATE.getAttr(), "enum.contract.attrName.cash_profit_rate", "cashProfitRate", FieldTypeEnum.NUM.getType(), SetTypeEnum.DISABLE_OPEN.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9780, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    /**
     * 资金管理一期改造，将以下字段进行修改，并新增
     * 修改字段：
     * 关联信息-->关联回款
     * 添加应收款-->应收款
     * 新增字段：
     * 坏账金额，坏账金额的变化由回款单的变化而变化
     * 核销预收款
     * 回款单
     */
    // 关联信息
    ASSOCIATED_INFO(ContractBaseEnum.ASSOCIATED_INFO.getAttr(), "enum.contract.attrName.associated_info", "associatedInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9770, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ADD_WRITE_OFF_PREPAYMENT(ContractBaseEnum.ADD_WRITE_OFF_PREPAYMENT.getAttr(), "enum.contract.attrName.add_write_off_prepayment", "addWriteOffPrepayment", FieldTypeEnum.LINK_FORM_BUTTON.getType(), 3, 0, 0, ShowTypeEnum.EDIT.getCode(), 9769, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ADD_PAYMENT_SHEET(ContractBaseEnum.ADD_PAYMENT_SHEET.getAttr(),"enum.contract.attrName.add_payment_sheet", "addPaymentSheet", FieldTypeEnum.LINK_FORM_BUTTON.getType(), 3, 0, 0, ShowTypeEnum.EDIT.getCode(), 9768, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    /**
     * 应收款
     */
    ADD_PAYMENT(ContractBaseEnum.ADD_PAYMENT.getAttr(), "enum.contract.attrName.add_payment", "addPayment", FieldTypeEnum.LINK_FORM.getType(), 3, 0, 0, ShowTypeEnum.EDIT.getCode(), 9760, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    
    // 扩展信息
    EXTEND_INFO(ContractBaseEnum.EXTEND_INFO.getAttr(), "enum.contract.attrName.extend_info", "extendInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9750, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    LINK_PARTNER_CUSTOMER(ContractBaseEnum.LINK_PARTNER_CUSTOMER.getAttr(), "enum.contract.attrName.link_partner_customer", "linkPartnerCustomer", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9740, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    TYPE(ContractBaseEnum.TYPE.getAttr(), "enum.contract.attrName.type", "type", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9730, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    PAY_METHOD(ContractBaseEnum.PAY_METHOD.getAttr(), "enum.contract.attrName.pay_method", "payMethod", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9720, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    EXPRESS_STATUS(ContractBaseEnum.EXPRESS_STATUS.getAttr(), "enum.contract.attrName.express_status", "expressStatus", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9710, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    SHIP_STATUS(ContractBaseEnum.SHIP_STATUS.getAttr(),"enum.contract.attrName.ship_status","shipStatus",FieldTypeEnum.COMBO.getType(),1,1,0,ShowTypeEnum.LIST_DETAIL.getCode(),9370,1,0,ScreenTypeEnum.SCREEN_GROUP.getType()),
    EXPRESS_NAME("text_11", "enum.contract.attrName.express_name", "expressName", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9700, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    EXPRESS_NO("text_12", "enum.contract.attrName.express_no", "expressNo", FieldTypeEnum.TEXT.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9690, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
   // 系统信息
    SYSTEM_INFO(ContractBaseEnum.SYSTEM_INFO.getAttr(),"enum.contract.attrName.system_info", "systemInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9680, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    CREATOR_ID(ContractBaseEnum.CREATOR_ID.getAttr(), "enum.contract.attrName.creator_id", "creatorId", FieldTypeEnum.CREATORID.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9670, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    ADD_TIME(ContractBaseEnum.ADD_TIME.getAttr(), "enum.contract.attrName.add_time", "addTime", FieldTypeEnum.ADDTIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9660, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    UPDATE_TIME(ContractBaseEnum.UPDATE_TIME.getAttr(), "enum.contract.attrName.update_time", "updateTime", FieldTypeEnum.UPDATETIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9650, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 须在列表页展示，不在新建和表单设计展示
    FINISH_AMOUNT(ContractBaseEnum.FINISH_AMOUNT.getAttr(), "enum.contract.attrName.finish_amount", "finishAmount", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.LIST.getCode(), 9640, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    UN_FINISH_AMOUNT(ContractBaseEnum.UN_FINISH_AMOUNT.getAttr(),"enum.contract.attrName.un_finish_amount", "unFinishAmount", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.LIST.getCode(), 9630, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    BAD_AMOUNT(ContractBaseEnum.BAD_AMOUNT.getAttr(), "enum.contract.attrName.bad_amount", "badAmount", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.LIST.getCode(), 9629, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    PAY_PERCENT(ContractBaseEnum.PAY_PERCENT.getAttr(), "enum.contract.attrName.pay_percent", "payPercent", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.LIST.getCode(), 9620, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    INVOICE_AMOUNT(ContractBaseEnum.INVOICE_AMOUNT.getAttr(), "enum.contract.attrName.invoice_amount", "invoiceAmount", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.LIST.getCode(), 9610, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    UN_INVOICE_AMOUNT(ContractBaseEnum.UN_INVOICE_AMOUNT .getAttr(), "enum.contract.attrName.un_invoice_amount", "unInvoiceAmount", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.LIST.getCode(), 9600, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 逻辑字段
    //TODO hiabin.zhang 币种发现两套格式了 暂时保留币种字段，默认为元不可编辑该字段
    IF_STATISTIC(ContractBaseEnum.IF_STATISTIC.getAttr(), "enum.contract.attrName.if_statistic", "ifStatistic", FieldTypeEnum.COMBO_NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9590, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    CURRENCY(ContractBaseEnum.CURRENCY.getAttr(), "enum.contract.attrName.currency", "currency", FieldTypeEnum.NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9580, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    EXCHANGE_RATE(ContractBaseEnum.EXCHANGE_RATE.getAttr(), "enum.contract.attrName.exchange_rate", "exchangeRate", FieldTypeEnum.NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9570, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    INSTOCK_ID(ContractBaseEnum.INSTOCK_ID.getAttr(), "enum.contract.attrName.instock_id", "instockId", FieldTypeEnum.COMBO_CHECK.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9560, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    OUTSTOCK_ID(ContractBaseEnum.OUTSTOCK_ID.getAttr(), "enum.contract.attrName.outstock_id", "outstockId", FieldTypeEnum.COMBO_CHECK.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9550, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    PURCHASE_ID(ContractBaseEnum.PURCHASE_ID.getAttr(), "enum.contract.attrName.purchase_id", "purchaseId", FieldTypeEnum.NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9540, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ALL_OUT_BOUND(ContractBaseEnum.ALL_OUT_BOUND.getAttr(), "enum.contract.attrName.all_out_bound", "allOutBound", FieldTypeEnum.COMBO_NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9530, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    IS_RED(ContractBaseEnum.IS_RED.getAttr(), "enum.contract.attrName.is_red", "isRed", FieldTypeEnum.COMBO_NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9520, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    HAS_RED(ContractBaseEnum.HAS_RED.getAttr(), "enum.contract.attrName.has_red", "hasRed", FieldTypeEnum.COMBO_NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9510, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ESTIMATE_COST(ContractBaseEnum.ESTIMATE_COST.getAttr(), "enum.contract.attrName.estimate_cost", "estimateCost", FieldTypeEnum.NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9500, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    REAL_COST(ContractBaseEnum.REAL_COST.getAttr(), "enum.contract.attrName.real_cost", "realCost", FieldTypeEnum.NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9490, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    SHOW_PRODUCE(ContractBaseEnum.SHOW_PRODUCE.getAttr(), "enum.contract.attrName.show_produce", "showProduce", FieldTypeEnum.COMBO_NUM.getType(), 1, 1, 1, ShowTypeEnum.NONE.getCode(), 9480, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    LINK_CUSTOMER_HIDE(ContractBaseEnum.LINK_CUSTOMER_HIDE.getAttr(), "enum.contract.attrName.link_customer_hide", "linkCustomerHide", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9470, 1, 1, ScreenTypeEnum.SCREEN_OFF.getType()),
    LINK_CONTACT_HIDE(ContractBaseEnum.LINK_CONTACT_HIDE.getAttr(), "enum.contract.attrName.link_contact_hide", "linkContactHide", FieldTypeEnum.TEXT.getType(), 3, 0, 1, ShowTypeEnum.NONE.getCode(), 9460, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    LINK_OPPORTUNITY_HIDE(ContractBaseEnum.LINK_OPPORTUNITY_HIDE.getAttr(), "enum.contract.attrName.link_opportunity_hide", "linkOpportunityHide", FieldTypeEnum.TEXT.getType(), 3, 0, 1, ShowTypeEnum.NONE.getCode(), 9450, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    LINK_PARTNER_CUSTOMER_HIDE(ContractBaseEnum.LINK_PARTNER_CUSTOMER_HIDE.getAttr(), "enum.contract.attrName.link_partner_customer_hide", "linkPartnerCustomerHide", FieldTypeEnum.TEXT.getType(), 3, 0, 1, ShowTypeEnum.NONE.getCode(), 9440, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
//    UNIT("text_13", "enum.contract.attrName.unit", "unit", FieldTypeEnum.COMBO.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9430, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ARCHIVED(ContractBaseEnum.ARCHIVED.getAttr(), "enum.contract.attrName.archived", "archived", FieldTypeEnum.COMBO_NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9420, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    SIGN_NAME(ContractBaseEnum.SIGN_NAME.getAttr(), "enum.contract.attrName.sign_name", "signName", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9420, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 新增字段
    QUOTATION_ID(ContractBaseEnum.QUOTATION_ID.getAttr(), "enum.contract.attrName.quotation_id", "quotationId", FieldTypeEnum.LINK_BUSINESS_SINGLE.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9400, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    QUOTATION_NAME(ContractBaseEnum.QUOTATION_NAME.getAttr(), "enum.contract.attrName.quotation_name", "quotationName", FieldTypeEnum.TEXT.getType(), 3, 0, 1, ShowTypeEnum.NONE.getCode(), 9390, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    DISCOUNT(ContractBaseEnum.DISCOUNT.getAttr(), "enum.contract.attrName.discount", "discount", FieldTypeEnum.NUM.getType(), 3, 1, 0, ShowTypeEnum.ALL.getCode(), 9380, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    //text_81：应收账期
    RECEIVABLE_PERIOD(ContractBaseEnum.RECEIVABLE_PERIOD.getAttr(), "enum.customerManagement.attrName.receivable_period", "receivablePeriod", FieldTypeEnum.ACCOUNT_PERIOD.getType(), 3, 1, 0, ShowTypeEnum.ALL.getCode(), 9370, 1, 1, ScreenTypeEnum.SCREEN_SHOW.getType()),
    // 已出库其他费用
    OUTSTOCK_OTHER_EXPENSE(ContractBaseEnum.OUTSTOCK_OTHER_EXPENSE.getAttr(), "enum.customerManagement.attrName.outstock_other_expense", "outstockOtherExpense", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9371, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 已出库优惠金额
    OUTSTOCK_DISCOUNT_AMOUNT(ContractBaseEnum.OUTSTOCK_DISCOUNT_AMOUNT.getAttr(), "enum.customerManagement.attrName.outstock_discount_amount", "outstockDiscountAmount", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9372, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),

    ;

    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 对应saas中的attr
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see com.xbongbong.paas.enums.FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     * 1.重命名+字段权限
     * 2.重命名+字段权限+查重
     * 3.重命名+字段权限+启用、必填
     * 4.重命名+字段权限+查重+启用、必填
     * 注：pro中启用和必填是同一个权限，同时启用或同时关闭
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     * 详见
     *
     * @see com.xbongbong.saas.enums.ShowTypeEnum
     */
    private Integer showType;
    /**
     * 字段在模板设计界面的排序
     * 建议不要用连续的数字，可以用等差数列，以防以后在两个字段之间加入新字段
     */
    private Integer sort;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;
    /**
     * 筛选类型
     * 1：可筛选
     * 2：不可筛选
     */
    private Integer screenType;

    ContractEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable,
                 Integer editHide, Integer showType, Integer sort, Integer visible, Integer required, Integer screenType) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.sort = sort;
        this.visible = visible;
        this.required = required;
        this.screenType = screenType;
    }

    /**
     * 对data内的字段拼上“data.”
     *
     * @param cache
     * @return java.lang.String
     * @author zcp
     * @date 2019/3/1 18:12
     * @version v1.0
     * @since v1.0
     */
    public static String getAttrConnectData(ContractEnum cache) {
        return "data." + cache.getAttr();
    }

    /**
     * 获取es查询、聚合字段
     * data在库内是json对象，对data字段内某个key做es【精确查询】时，需要在其前拼上“data.”，且【text等类型的】要在后面拼“.keyword”
     *
     * @param cache 当前枚举对象
     * @return java.lang.String 处理后的聚合字段
     * @author zcp
     * @date 2019/2/21 14:59
     * @version v1.0
     * @since v1.0
     */
    public static String getEsAttr4Keyword(ContractEnum cache) {
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(cache.fieldType);
        //字段类型为text，或者字段在es内的类型时text，则需要在后面拼上“.keyword”
        boolean flag = fieldTypeEnum == FieldTypeEnum.TEXT || "text".equals(fieldTypeEnum.getEsalias());
        if (flag) {
            return "data." + cache.getAttr() + ".keyword";
        }
        return "data." + cache.getAttr();
    }

    public static List<JSONObject> getWaitTabHeadd() {
        JSONObject radioCheck = new JSONObject();
        radioCheck.put("prop", FieldTypeEnum.HEAD_CHECKBOX_GROUP.getAlias());
        radioCheck.put("fieldType", FieldTypeEnum.HEAD_CHECKBOX_GROUP.getType());
        radioCheck.put("label", FieldTypeEnum.HEAD_CHECKBOX_GROUP.getDescription());
        JSONObject contractName = new JSONObject();
        contractName.put("prop", "contractName");
        contractName.put("fieldType", ContractEnum.NAME.fieldType);
        contractName.put("label", ContractEnum.NAME.getAttrName());
        JSONObject contractNo = new JSONObject();
        contractNo.put("prop", "contractNo");
        contractNo.put("fieldType", ContractEnum.CONTRACT_NO.fieldType);
        contractNo.put("label", ContractEnum.CONTRACT_NO.getAttrName());
        JSONObject customerName = new JSONObject();
        customerName.put("prop", "customerName");
        customerName.put("fieldType", ContractEnum.LINK_CUSTOMER.fieldType);
        customerName.put("label", ContractEnum.LINK_CUSTOMER.getAttrName());
        return Arrays.asList(radioCheck, contractName, contractNo, customerName);

    }

    /**
     * 流程中获取隐藏字段
     *
     * @return
     */
    public static List<ContractEnum> getDisableField() {
        List<ContractEnum> contractEnums = new ArrayList<>();
        for (ContractEnum contractEnum : values()) {
            if (Objects.equals(contractEnum.getShowType(), ShowTypeEnum.NONE.getCode()) || Objects.equals(contractEnum.getEditHide(), 1)
                    || Objects.equals(contractEnum.getFieldType(), FieldTypeEnum.CREATORID.getType()) || Objects.equals(contractEnum.getFieldType(), FieldTypeEnum.ADDTIME.getType())) {
                contractEnums.add(contractEnum);
            }
        }
        return contractEnums;
    }

    /**
     * app端详情默认标题显示字段
     *
     * @return List
     * @author GuoJun.HU
     * @date 2019/4/8 19:21
     * @since V1.0
     */
    public static List<Object> getTitleAttrList() {
        return Collections.singletonList(CONTRACT_NO);
    }

    /**
     * 默认标签
     *
     * @author long.rao
     * @date 2019-06-27 15:36
     */
    public static List<Object> getLabelAttrList() {
        return Collections.singletonList(STATUS);
    }

    /**
     * 详情默认摘要
     *
     * @author long.rao
     * @date 2019-06-27 15:47
     */
    public static List<Object> getSummaryAttrList() {
        return Arrays.asList(NAME, LINK_CUSTOMER, SIGN_PERSON, SIGN_TIME);
    }

    /**
     * 把传入的字段（类型为LINK_BUSINESS_SINGLE）的转为其隐藏字段
     * @param attr 字段名
     * @return java.lang.String
     * @author zcp
     * @date 2019/7/4 15:31
     * @since v1.0
     * @version v1.0
     */
    public static String changeToHide4Link(String attr) {
        if (Objects.equals(attr, LINK_CUSTOMER.attr)) {
            return LINK_CUSTOMER_HIDE.attr;
        } else if (Objects.equals(attr, LINK_CONTACT.attr)) {
            return LINK_CONTACT_HIDE.attr;
        } else if (Objects.equals(attr, LINK_OPPORTUNITY.attr)) {
            return LINK_OPPORTUNITY_HIDE.attr;
        } else if (Objects.equals(attr, LINK_PARTNER_CUSTOMER.attr)) {
            return LINK_PARTNER_CUSTOMER_HIDE.attr;
        } else if (Objects.equals(attr, QUOTATION_ID.attr)) {
            return QUOTATION_NAME.attr;
        }
        return attr;
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    public static String getI18nValue(String value) {
        return I18nMessageUtil.getMessage(value);
    }
}
